package com.study.concurrentprogramming.park;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Description : park test
 * @Author : guxuemin
 * @Version : V1.0.0
 * @Date : 2021/8/24 22:12
 */
@Slf4j
public class ParkTest {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            log.info("t1 start");
            try {
                TimeUnit.SECONDS.sleep(3);
                log.info("t1 park");
                LockSupport.park();
                log.info("t1 resume ... ");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1");
        t1.start();
        TimeUnit.SECONDS.sleep(10);
        log.info("main thread resume t1");
        LockSupport.unpark(t1);


       // if (p == head && tryAcquire(arg)) {
            //    private void setHead(Node node) {
            //      head = node;
            //		node.thread = null;
            //      node.prev = null;
            //	}
       //     setHead(node);
       //     p.next = null; // help GC  相当于p.next,node.pre都是null，p节点就没有引用了，会被下次GC释放的
       //     failed = false;
       //     return interrupted;
       // }

    }
}
